﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    public class WB13QIReport : BaseReport
    {
        string strCompany = "HLT";
        string strExcelFile = "";
        public WB13QIReport()
            : base()
        {
            AssignColumns();
        }
        public WB13QIReport(Dictionary<string, object> dicParamater)
            : base(dicParamater)
        {
            strCompany = dicParamater["Company"].ToString().Trim();
            strExcelFile = dicParamater["ExcelFile"].ToString().Trim();
            AssignColumns();
        }
        private void AssignColumns()
        {
            columns.Clear();
            columns.Add("ARTICLE"); 
            columns.Add("WBBBESCHICH"); 
            columns.Add("COLORDES"); 
            columns.Add("WBBEINDAT"); 
            columns.Add("WBBDPART");
            columns.Add("PCNUM");
            columns.Add("MTR");
            columns.Add("REMARK");
            
            //ARTICLE,A.WBBBESCHICH,E.COLORDES,A.WBBFLZZUGDAT AS WBBEINDAT,A.WBBDPART,PCNUM,MTR,F.REMARK  
        }
        public void FillInExcelData(ArrayList columns, DataSet setSoruce, int xStart = 2, int yStart = 1)
        {
            try
            {
                
                int x = xStart, y = yStart;
                DataTable dtSoruce = setSoruce.Tables["WB13QI"];
                foreach (DataRow dataRow in dtSoruce.Rows)
                {
                    y = yStart;
                    foreach (string column in columns)
                    {
                        exAgent.SetCellValue(x, y, dataRow[column].ToString());
                        y++;
                    }
                    x++;
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public void REPORT2EXCEL(string fileType)
        {
            Queue CellQueue = new Queue();
            string filename = "";
            string sheetName = "";
            string Standard = "HLTWB13QI";
            strExcelFile = @"HLT\HLTSummaryReport.xls";
            string filePath = @"C:\intex.w\Report\" + strExcelFile;
            exAgent.Open(filePath);
            exAgent.Company = "";
            exAgent.strExcelFile = strExcelFile;
            string filedate = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
            filename = @"Warehouse\成品库存质量情况" + filedate + ".xls";
            sheetName = DateTime.Now.ToShortTimeString().Replace(@":", "");
            exAgent.CreateNewSheet(filename, Standard, sheetName);
            FillInExcelData(columns, dsSource, 3, 1);
            if (exAgent != null)
            {
                exAgent.Save();
                exAgent.Close();
            }
        }  
    }
    }


